<?php 
	Class Index extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model("model_custompackage");
			$this->load->model("model_package");
			$this->load->model("model_packagereview");
			$this->load->model("model_hotel");
			$this->load->model("model_hotelreview");
			$this->load->model("model_hotelroom");
			$this->load->model("model_hotelroomprice");
			$this->load->model("model_restaurant");
			$this->load->model("model_restaurantreview");
			$this->load->model("model_activity");
			$this->load->model("model_activityreview");
			$this->load->model("model_destination");
			$this->load->model("model_destinationreview");
			$this->load->model("model_flight");
			$this->load->model("model_car");
			$this->load->model("model_guild");
            //$this->output->enable_profiler();
		}
		public function index(){		
			$data["designedbyourguest"]=$this->model_custompackage->listall(6,0);		
			//start best deal	
			$data["bestdeal"]=$this->model_package->listall(1000000000,0);
			$data["topbestdeal"]=$this->model_package->listall(3,0);
			foreach($data["topbestdeal"] as &$listbestdeal){				
				$listbestdeal["bestdealreview"]=$this->model_packagereview->getall_colum_id("packageid",$listbestdeal["id"]);
				if(count($listbestdeal["bestdealreview"])>0){
					$total_review=0;
					foreach($listbestdeal["bestdealreview"] as $total_bdr){
						$total_review+=$total_bdr["mark"];					
					}	
					$listbestdeal["numberstar"]=floor($total_review/count($listbestdeal["bestdealreview"]));
				}else $listbestdeal["numberstar"]=0;
			}
			
			//start best selling hotel
			$data["bestsellinghotel"]=$this->model_hotel->listall(1000000000,0);
			$data["topbestselling"]=$this->model_hotel->listall(3,0);
			
			foreach($data["topbestselling"] as &$listbestselling){
				$priceminest=$this->model_hotel->priceminest($listbestselling["id"]);
				if(count($priceminest)>0) $listbestselling["priceminest"]=$priceminest[0]['price'];
				else $listbestselling["priceminest"]=0;
				$listbestselling["bestsellingreview"]=$this->model_hotelreview->getall_colum_id("hotelid",$listbestselling["id"]);
				if(count($listbestselling["bestsellingreview"])>0){
					$total_selling_review=0;
					foreach($listbestselling["bestsellingreview"] as $total_bsh){						
						$total_selling_review+=$total_bsh["mark"];						
					}					
					$listbestselling["numberstarreview"]=floor($total_selling_review/count($listbestselling["bestsellingreview"]));
				}else $listbestselling["numberstarreview"]=0;
				
			}
			//start activities traveler recommend			
			$activities_trv_rcmd=$this->model_activity->countrow();
			$data["activities_trv_rcmd"]=$activities_trv_rcmd;//count all row
			$data["topactivities"]=$this->model_activity->listall(6,0);
			
			foreach($data["topactivities"] as &$listactivities){
				$listactivities["review"]=$this->model_activityreview->getreview_column_id("mark",$listactivities["id"]);
				$total_activity_review=0;
				foreach($listactivities["review"] as $total_atr){
					$total_activity_review+=$total_atr["mark"];
				}
				$listactivities["acitivitystar"]=floor($total_activity_review/count($listactivities["review"]));
			}	
			
			//start destinations of the month
			$data["count_destination"]=$this->model_destination->countrow();
			$data["listdestination1"]=$this->model_destination->listall(3,0);
			foreach($data["listdestination1"] as &$listdestination){
				$listdestination["review"]=$this->model_destinationreview->getreview_column_id("mark",$listdestination["id"]);	
				$total_destination_review=0;
				foreach($listdestination["review"] as $total_des){
					$total_destination_review+=$total_des["mark"];
				}
				$listdestination["destinationstar"]=floor($total_destination_review/count($listdestination["review"]));
			}
			//list name in fixmenu
			$data['listname_restaurant']=$this->model_restaurant->listall_name();
			//get banner hotel
			$data['banner_hotel']=$this->model_hotel->getallbanner();
			
			$data['banner']="usercontrol/banner";
			$data["template"]="content";
			$this->load->view("layout",$data);
		}
		public function signin_signout(){
			$data["template"]="signin_signout";
			$this->load->view("layout",$data);
		}
		public function faq(){
			$data["template"]="faq";
			$this->load->view("layout",$data);
		}
		public function flights_search_result_page(){
			$data["template"]="flights_search_result_page";
			$this->load->view("layout",$data);
		}
		
		public function restaurant_detail(){
			$data["template"]="restaurant_detail";
			$this->load->view("layout",$data);
		}
		
		public function blog(){
			$data["template"]="blog";
			$this->load->view("layout",$data);
		}
		public function confirmation_artboard(){
			$data["template"]="confirmation_artboard";
			$this->load->view("confirmation_artboard",$data);
		}
	}
?>